<template>
	
	<view class="company-box">
		<u-skeleton rows="2" :loading="loading" avatar au-skeletonvatarSize="44" avatarShape="square"  :title="false" >
			<view class="company-top">
				<view class="company-logo">
					<image src="https://img.bidcenter.com.cn/uni/qiqing/companay.png" mode="widthFix"></image>
				</view>
				<view class="company-title">
					<view class="gongsimingcheng">
						<text>{{ companyData.name ? companyData.name :companyName }}</text>
						<image src="https://img.bidcenter.com.cn/uni/qiqing/gengxin.png" :class="isrotate ? 'imgIconRotate' : ''" @click="updateFn()"></image>
					</view>
					<view class="xinyongdaima" v-if="companyData.base_tax_number !=='--'">
						<text>{{companyData.base_tax_number}}</text>
					</view>
					<view class="gongsizhuagntai">
						<view class="status" v-if="companyData.base_reg_status&&companyData.base_reg_status !=='--'">{{companyData.base_reg_status}}</view>
						<view class="shenfen" @click="shenfenChange">
							<view >
								{{shenfenType==2 ? '业主' : shenfenType == 5 ? '供应商' : '代理机构'}}
							</view>
							<image src="https://img.bidcenter.com.cn/uni/qiqing/qiehuan.png" mode="widthFix" ></image>
						</view>
					</view>
				</view>
			</view>
		</u-skeleton>
		<u-skeleton rows="1" :loading="loading" rowsHeight="124" :title="false" style="margin-top: 20rpx;">
		<view class="company-bottom">
			<view class="faren">
				<view class="faren-item">
					<view v-if="shenfenType==2">近1年采购次数</view>
					<view v-if="shenfenType==5">近1年中标次数</view>
					<view v-if="shenfenType==1">近1年代理次数</view>
					<view>{{cishu}}次</view>
				</view>
				<view class="faren-item">
					<view v-if="shenfenType==2">近1年采购总金额</view>
					<view v-if="shenfenType==5">近1年中标总金额</view>
					<view v-if="shenfenType==1">近1年代理总金额</view>
					<view>{{zongjine}}{{unit}}元</view>
				</view>
				<view class="faren-item">
					<view v-if="shenfenType==2">最新招标时间</view>
					<view v-if="shenfenType==5">最新中标时间</view>
					<view v-if="shenfenType==1">最新代理时间</view>
					<view>{{lasttime}}</view>
				</view>
				<!-- <view class="faren-item">
					<view>企业法人</view>
					<view>{{companyData.base_faren ?companyData.base_faren :'-'}}</view>
				</view>
				<view class="faren-item">
					<view>注册资本</view>
					<view>{{companyData.base_reg_jine && companyData.base_reg_jine !==0 ? companyData.base_reg_jine :'-'}}</view>
				</view>
				<view class="faren-item">
					<view>成立日期</view>
					<view>{{companyData.base_estiblish_time ? companyData.base_estiblish_time :'-'}}</view>
				</view> -->
			</view>
			<view class="qita">
				<view class="guanwang" @click="toCopy('guanwang',companyData.base_website_list)" >
					<image src="https://img.bidcenter.com.cn/uni/qiqing/wangzhi.png" mode="widthFix"></image>
					<text>官网</text>
					<text style="display: none;">{{ companyData.base_website_list }}</text>
				</view>
				<view class="dizhi" @click="toCopy('dizhi',companyData.base_reg_dizhi)">
					<image src="https://img.bidcenter.com.cn/uni/qiqing/dizhi.png" mode="widthFix"></image>
					<text>地址</text>
					<text style="display: none;">{{ companyData.base_reg_dizhi }}</text>
				</view>
				<view class="lianxifangshi">
					<text>联系方式：{{ companyData.base_phone ? companyData.base_phone  :'-'}}</text>
					<u-loading-icon v-if='totalCountLoading'></u-loading-icon>
					<label v-else>
						<text @click="moreClick" v-if="totalCount>0">更多{{totalCount}}+</text>
					<text @click="moreClick" v-else>更多</text>
					</label>
					
				</view>
			</view>
		</view>
		</u-skeleton>
		<!-- 身份切换弹窗 -->
		<u-popup :show="shenfenShow" :round="10" mode="center" :closeable="true" @close="shenfenClose">
			<view class="shenfen-box">
				<view class="title">
					选择企业身份
				</view>
				<view class="shenfen-item d-c-c" :class="shenfenType==2 ? 'active' :''" @click="shenfenClick('2')">
					<img src="https://img.bidcenter.com.cn/uni/qiqing/yezhu.png" alt="" class="shenfen-img">
					<text>业主</text>
				</view>
				<view class="shenfen-item d-c-c" :class="shenfenType==5 ? 'active' :''"@click="shenfenClick('5')">
					<img src="https://img.bidcenter.com.cn/uni/qiqing/gongyingshang.png" alt=""  class="shenfen-img">
					<text>供应商</text>
				</view>
				<view class="shenfen-item d-c-c" :class="shenfenType==1 ? 'active' :''" @click="shenfenClick('1')">
					<img src="https://img.bidcenter.com.cn/uni/qiqing/dailijigou.png" alt=""  class="shenfen-img">
					<text>代理机构</text>
				</view>
			</view>
		</u-popup>
		
		<!-- 复制弹窗----样式在common.scss中公共弹窗样式-->
		<u-popup :show="copyShow" :round="10" mode="center" :closeable="true" :safeAreaInsetBottom="false" @close="copyClose">
			<view class="gonggongtanchuang">
				<view class="title">
					{{copyType=="dizhi" ? '地址' :'网址'}}
				</view>
				<view class="cont">
					{{copyContent}}
				</view>
				<view class="btn">
					<view @click="copySumit">
						复制
					</view>
					<view @click="copyClose">
						取消
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		props:['companyData','danweiType',"location","comcode","vcode","fromCompanyInfo","isJiankong","jiankongLoading","tabList","tabIndex","tabName","companyName",'ids','qytype'],
		data() {
			const danweiType = this.danweiType
			return {
				
				shenfenShow:false,
				shenfenType:danweiType || '2',
				loading:true,
				isrotate:false,
				//复制弹窗
				copyShow:false,
				copyType:'dizhi',
				copyContent:'',
				totalCount:0,
				totalCountLoading:true,
				cishu:'0',
				zongjine:'0',
				lasttime:'-',
				unit:'',
				userInfo:uni.getStorageSync('userInfo') || {},
				lock:false,
			}	
		},
		
		 created() {
			
		},
		mounted() {
			if(this.userInfo && !this.userInfo.isLogin){
				return
			}
			//如果需要子组件完全挂载之后在执行操作可以使用$nextTick
			this.$nextTick(()=>{
				
				this.getCompanyInfo()
				this.getShuliang()
				this.getTongji()
			})
			// console.log(this.shenfenType,this.comcode,this.vcode)
		},
		watch: {
			danweiType(a, b) {
				//10-提及单位，当为提及单位时不更新，bug:企情分析切换单位类型时，会自动切换当前身份类型，上面的次数字段名称也消失了
				if(a !==b && a !='10'){
					this.shenfenType=a
				}
			}
		},
		
		methods: {
			//获取联系人数量--20250421修改接口
			// getShuliang(){
			// 	const paramsNew = {
			// 			location: this.location,
			// 			id:this.ids,
			// 			type:this.qytype
			// 		}
			// 	uni.$u.http
			// 		.post('/zhaobiao/CompanyExtendHandler.ashx', paramsNew) 
			// 		.then(rs => {
			// 			this.totalCount=rs.lxrCount
			// 			this.totalCountLoading=false
			// 		}).catch(err => {
			// 			uni.$u.toast(err.msg || '接口异常');
			// 		});
			// },
			//获取联系人数量--最新，用这个接口
			getShuliang(){
				const paramsNew = {
						location: this.location,
						comcode:this.comcode,
						vcode:this.vcode,
						tjtypes:1
					}
				uni.$u.http
					.post('/analysis/Company/CompanyTongji.ashx', paramsNew) 
					.then(rs => {
						this.totalCount=rs.tj_1
						this.totalCountLoading=false
					}).catch(err => {
						uni.$u.toast(err.msg || '接口异常');
					});
			},
			//获取公司信息
			getCompanyInfo(){
				this.loading=true
				uni.$u.http
					.post('/analysis/Company/CompanyInfoHandler.ashx', {
						comcode: this.comcode,
						vcode: this.vcode,
						location: this.location,
						comType:this.shenfenType,//1：代理；2：业主；4/5：供应商
					})
					.then(rs => {
						this.loading=false
						const data = rs.companyinfo;
						  data.base_estiblish_time =
							(data.base_estiblish_time &&
							 uni.$u.timeFormat(data.base_estiblish_time,'yyyy/mm/dd'))||
							"--";
							
						  data.base_from_time =
							(data.base_from_time &&
							 uni.$u.timeFormat(new Date(data.base_from_time),'yyyy/mm/dd')) ||
							"--";
							
							if(data.base_to_time){
								if(!data.base_to_time.includes('固定期限')){
								  data.base_to_time =uni.$u.timeFormat(new Date(data.base_to_time),'yyyy/mm/dd')
								  // console.log(111,data.base_to_time)
								}
							  }else{
								data.base_to_time= "--"
							  }
						 
						  data.base_update_time =
							(data.base_update_time &&
							  uni.$u.timeFormat(data.base_update_time,'yyyy/mm/dd')) ||
							"--";
							// data.base_tax_number=data.base_tax_number.includes('企业没有纳税人识别号') ? '':data.base_tax_number
							data.base_tax_number=data.base_tax_number==null ||data.base_tax_number.includes('企业没有纳税人识别号') ? '':data.base_tax_number
						  // 去除前后空格
						  for (const key in data) {
							if (typeof data[key] === "string") {
							  data[key] = data[key].trim();
							}
				
							if (!data[key]) {
							  data[key] = "--";
							}
						}
						data.shangxian = rs.limitCount - rs.currCount>0 ?false :true
						
						// debugger
						this.$emit("update:companyData", data);
						this.$emit("update:isJiankong", rs.isshoucang);
						this.$emit("update:jiankongLoading", false);
					}).catch(err => {
						//日访问量已达上限
						let data={}
						if(err.retbs==998){
							data.shangxian=true
							this.$emit("update:companyData", data);
						}
						uni.$u.toast(err.msg || '接口异常');
						this.$emit("update:jiankongLoading", false);
					});
				
			},
			
			// 点击刷新按钮
			updateFn() {
				this.lock=true
				this.isrotate = true;
			  uni.$u.http
			  	.post('/analysis/Company/CompanyUpdateHandler.ashx', {
				  comcode: this.comcode,
				  vcode: this.vcode,
				})
				.then((rs) => {
				  // biaoshi 1为数据已更新 2为已提交申请
				  const biaoshi = rs.biaoshi;
				  const me = this;
				  this.getCompanyInfo()
				  setTimeout(() => {
					// 需要延迟的代码 :3秒后延迟跳转到首页，可以加提示什么的
					uni.showToast({
					  title: biaoshi === 2 ? "已提交申请" : "数据已更新",
					  icon: "success",
					});
					me.isrotate = false;
					this.lock=false
					// 延迟时间：2秒
				  }, 1000);
				})
				.catch((err) => {
				  console.log(err);
				  uni.$u.toast(err.msg || '更新接口异常');
				});
			},
			//点击顶部身份切换
			shenfenChange(){
				this.shenfenShow=true
			},
			//身份弹窗关闭
			shenfenClose(){
				this.shenfenShow=false
			},
			
			//身份弹窗---选择身份
			shenfenClick(type){
				this.shenfenType=type
				this.shenfenShow=false
				this.$emit('update:danweiType',type)
				this.$emit("update:fromCompanyInfo", true)
				this.getTongji()
			},
			//复制弹窗关闭
			copyClose(){
				this.copyShow=false
			},
			toCopy(type,content){
				if(content =='--' || content ==undefined || content ==null){
					uni.$u.toast('暂无数据');
				}else{
					this.copyShow=true
					this.copyType=type
					this.copyContent=content
				}
				
			},
			copySumit(){
				
				uni.setClipboardData({
					data:this.copyContent,
					success: () => {
						this.copyShow = false
					},
					fail:(error)=> {
						console.log('失败',error);
						uni.showToast({
							title: '复制失败',
							icon: 'none'
						});
					}
								
				})
			},
			//更多
			moreClick(){
				this.$emit("update:tabName", '找人脉')
				let index=2
				if(this.tabList[0].name=="企业信息库"){
					index=3
					this.$emit("update:tabIndex", 3)
				}else{
					index=2
				}
				this.$emit("update:tabIndex", index)
				//更新查看次数权限
				let obj={
					name:'找人脉',
					index:index
				}
				this.$emit("tabClick", obj)
			},
			
			//统计
			getTongji(){
				//2--业主  5--供应商 1--代理
				if(this.shenfenType==2){
					uni.$u.http
						.post('/analysis/Company/partA/GaikuangHandler.ashx', {
					  comcode: this.comcode,
					  vcode: this.vcode,
					  time:1,
					})
					.then((rs) => {
						this.cishu=rs.zhaobiaocount.cishu
						this.zongjine=rs.zhaobiaojine.jine
						this.unit=rs.zhaobiaojine.ave_unit
						this.lasttime= rs.lasttime !=='--' ? uni.$u.timeFormat(rs.lasttime,'yyyy-mm-dd') :'-'
					})
					.catch((err) => {
					  console.log(err);
					  uni.$u.toast(err.msg || '统计接口异常');
					});
				}else if(this.shenfenType==5){
					uni.$u.http
						.post('/analysis/Company/partB/GaikuangHandler.ashx', {
					  comcode: this.comcode,
					  vcode: this.vcode,
					  time:1,
					})
					.then((rs) => {
						this.cishu=rs.zhongbiaocount.cishu
						this.zongjine=rs.zhongbiaojine.jine
						this.unit=rs.zhongbiaojine.ave_unit
						this.lasttime= rs.lasttime !=='--' ? uni.$u.timeFormat(rs.lasttime,'yyyy-mm-dd') :'-'
					})
					.catch((err) => {
					  console.log(err);
					  uni.$u.toast(err.msg || '统计接口异常');
					});
				}else{
					uni.$u.http
						.post('/analysis/Company/agent/GaikuangHandler.ashx', {
					  comcode: this.comcode,
					  vcode: this.vcode,
					  time:1,
					})
					.then((rs) => {
						this.cishu=rs.zhaobiaocount.cishu
						this.zongjine=rs.zhongbiaojine.jine
						this.unit=rs.zhongbiaojine.ave_unit
						this.lasttime= rs.lasttime !=='--' ? uni.$u.timeFormat(rs.lasttime,'yyyy-mm-dd') :'-'
					})
					.catch((err) => {
					  console.log(err);
					  // uni.$u.toast(err.msg || '统计接口异常');
					});
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	@import "@/static/css/index.scss";
	.company-box {
		padding: 20rpx 28rpx;
		background: #fff;
		
	}

	::v-deep .company-bottom {
		margin-top: 20rpx;
		background: #F2F4F7;
		border-radius: 10rpx;
		
	}
	
	//身份弹窗
	.shenfen-box{
		width: 600rpx;
		padding: 60rpx 30rpx 40rpx;
		box-sizing: border-box;
		.title{
			margin-bottom: 60rpx;
			font-weight: bold;
			font-size: 36rpx;
			color: #3B3E45;
			text-align: center;
		}
		.shenfen-item{
			line-height: 170rpx;
			box-sizing: border-box;
			margin-bottom: 20rpx;
			border-radius: 10rpx;
			border: 1rpx solid #DDDDDD;
			background: transparent;
			transform: rotateZ(360deg);
			&.active{
				border-color: #2F6DFE;
				background: rgba(47,109,254,0.1);
			}
			.shenfen-img{
				width: 88rpx;
				height: 98rpx;
				margin-right: 40rpx;
			}
			text{
				font-size: 36rpx;
				color: #3B3E45;
				font-weight: bold;
			}
		}
	}
	.u-popup  ::v-deep  .u-icon__icon{
		color: #3B3E45 !important;
	}
	.imgIconRotate {
	  vertical-align: middle;
	  animation: rotate 1.5s linear 2;
	}
	@keyframes rotate {
	  0% {
	    transform: rotate(0deg);
	  }
	
	  100% {
	    transform: rotate(360deg);
	  }
	}
	::v-deep .u-skeleton{
		.company-top {
			display: flex;
			.company-logo {
				height: 88rpx;
				margin-right: 14rpx;
		
				image {
					width: 88rpx;
					height: 88rpx;
				}
			}
		
			.company-title {
				width: 86%;
				margin-top: 4rpx;
			}
		
			.gongsimingcheng {
				display: flex;
				align-items: center;
				width: 92%;
				text {
					font-size: 28rpx;
					color: #3B3E45;
					font-weight: bold;
					white-space: pre-wrap;
					max-width: 93%;
				}
		
				image {
					width: 32rpx !important;
					height: 32rpx;
					margin-left: 10rpx;
					
				}
			}
			.xinyongdaima{
				text {
					font-size: 24rpx;
					color: #ADB4C2;
					margin-right: 10rpx;
				}
			}
			.gongsizhuagntai {
				display: flex;
				margin-top: 8rpx;
				.status,.shenfen view {
					padding: 0 12rpx;
					height: 40rpx;
					line-height: 40rpx;
					font-size: 22rpx;
					color: #2F6DFE;
					text-align: center;
					background: rgba(47, 109, 254, 0.1);
					border-radius: 6rpx;
					margin-right: 10rpx;
				}
				.shenfen{
					display: flex;
					align-items: center;
				}
				image {
					width: 32rpx;
					height: 32rpx;
				}
			}
		}
		.faren {
			display: flex;
			padding: 30rpx 0;
			border-bottom: 1rpx solid #E8E8E8;
		
			.faren-item {
				flex: 1;
				text-align: center;
		
				view:first-child {
					font-size: 24rpx;
					color: #6C717E;
				}
		
				view:last-child {
					margin-top: 14rpx;
					font-size: 28rpx;
					color: #3B3E45;
					font-weight: bold;
				}
			}
		}
		
		.qita {
			display: flex;
			align-items: center;
			padding: 0 30rpx;
			line-height: 92rpx;
		
			image {
				width: 32rpx;
				height: 32rpx;
				vertical-align: middle;
				margin-top: -4rpx;
			}
		
			text {
				font-size: 24rpx;
				line-height: 92rpx;
			}
		
			.guanwang,
			.dizhi {
				color: #2F6DFE;
				margin-right: 30rpx;
				white-space: nowrap;
		
				image {
					margin-right: 4rpx;
				}
			}
		
			.lianxifangshi {
				width: 64%;
				display: flex;
				justify-content: space-between;
				white-space: nowrap;
				align-items: center;
				text {
					&:first-child {
						color: #6C717E;
					}
		
					&:last-child {
						color: #FE6B2F;
					}
				}
			}
		}
		view{
			display: block;
			flex-direction: initial;
		}
	}
	// 公共弹窗样式1
	.gonggongtanchuang{
		width: 600rpx;
		height: 357rpx;
		padding-top: 50rpx;
		text-align: center;
		.title{
			font-size: 36rpx;
			color: #333;
			font-weight: bold;
		}
		.cont{
			height: 148rpx;
			padding:0 48rpx;
			margin-top: 60rpx;
			font-size: 28rpx;
			color: #6F6F6F;
			overflow:hidden;
			text-overflow:ellipsis;
		}
		.btn{
			display: flex;
			border-top: 1rpx solid #D8D8D8;
			view{
				flex:1;
				height: 96rpx;
				line-height: 96rpx;
				font-size: 32rpx;
				&:first-child{
					color: #2F7FFF;
					font-weight: bold;
					border-right:1rpx solid #D8D8D8;
				}
			}
		}
	}
	::v-deep.u-skeleton .u-skeleton__wrapper__content__rows{
		width: 100% !important;
	}
</style>